<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible">
    <el-form :model="form">
      <el-form-item label="发卡数量" :label-width="formLabelWidth">
        <el-input v-model="form.number" placeholder="请输入发卡数量"></el-input>
      </el-form-item>
      <el-form-item label="卡种类型" :label-width="formLabelWidth">
        <el-select v-model="form.id" placeholder="请选择" style="width: 100%">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="mit">取 消</el-button>
      <el-button type="primary" @click="onSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {issueCards,issueCardList} from "@/api/user/user"
export default {
  data() {
    return{
      title:'发卡',
      dialogFormVisible:false,
      formLabelWidth: '120px',
      options: [],
      form: {
        id: undefined,
        number: undefined,
        userid: undefined
      },
    }
  },
  methods:{
    async getissueCardList(){
      let res = await issueCardList()
      this.options = res.data.map(item => {
        return {
          value: item.id,
          label:item.vipName
        }
      })
    },
    async onSubmit(){
      if(!this.form.number){
        this.$message({
          message: '请输入数量',
          type: 'warning'
        });
        return;
      }
      await issueCards(this.form)
      this.$message({
        type: 'success',
        message: '发卡成功'
      });
      this.dialogFormVisible = false
      this.setForm()
    },
    setForm(){
      this.form.id=undefined
      this.form.number=undefined
      this.form.userid = undefined
    },
    open(userid){
      this.form.userid = userid
      this.dialogFormVisible = true
      this.getissueCardList()
    },
    mit(){
      this.dialogFormVisible = false
      this.setForm()
    }
  }
}
</script>
<style scoped lang="scss">

</style>
